#!/bin/sh

scons -c

TOOLCHAIN=pepper_15
ARCHITECTURE=i686
#VARIANT=glibc
VARIANT=newlib

SYSTEM=linux_x86

if [ "$VARIANT" = "newlib" ]
then
  SYSTEM=${SYSTEM}_${VARIANT}
fi

export NACL_SDK_USR_INCLUDE=${NACL_SDK_ROOT}/$TOOLCHAIN/toolchain/$SYSTEM/$ARCHITECTURE-nacl/usr/include
export NACL_SDK_USR_LIB=${NACL_SDK_ROOT}/$TOOLCHAIN/toolchain/$SYSTEM/$ARCHITECTURE-nacl/usr/lib

scons --nacl-platform=$TOOLCHAIN --variant="${VARIANT}" chrome-ssh_x86_32_dbg.nexe

if [ $? -ne 0 ]
then
  echo "x86-32 DEBUG BUILD FAILED!"
  exit 1
fi

scons --nacl-platform=$TOOLCHAIN --variant="${VARIANT}" chrome-ssh_x86_32.nexe

if [ $? -ne 0 ]
then
  echo "x86-32 BUILD FAILED!"
  exit 1
fi

ARCHITECTURE=x86_64

export NACL_SDK_USR_INCLUDE=${NACL_SDK_ROOT}/$TOOLCHAIN/toolchain/$SYSTEM/$ARCHITECTURE-nacl/usr/include
export NACL_SDK_USR_LIB=${NACL_SDK_ROOT}/$TOOLCHAIN/toolchain/$SYSTEM/$ARCHITECTURE-nacl/usr/lib

scons --nacl-platform=$TOOLCHAIN --variant="${VARIANT}" chrome-ssh_x86_64_dbg.nexe

if [ $? -ne 0 ]
then
  echo "x86-64 DEBUG BUILD FAILED!"
  exit 1
fi

scons --nacl-platform=$TOOLCHAIN --variant="${VARIANT}" chrome-ssh_x86_64.nexe

if [ $? -ne 0 ]
then
  echo "x86-64 BUILD FAILED!"
  exit 1
fi

scons --nacl-platform=$TOOLCHAIN --variant="${VARIANT}" chrome-ssh.nmf

if [ $? -ne 0 ]
then
  echo "NMF BUILD FAILED!"
  exit 1
fi

echo !!! SUCCESS !!!
